<?php
class GridToolButton{
	protected $_girdPrototype;
	public $htmlOptions = array();
	
	public $type;
	public $label;
	public $url;
	
	
	public function setPrototype($grid){
		$this->_girdPrototype = $grid;
	}
	
	public function getPrototype(){
		return $this->_girdPrototype;
	}
	
	public function button(){
		$this->buttonEvent();
		return CHtml::htmlButton($this->label,$this->htmlOptions);
	}

	public function buttonEvent(){
		switch ($this->type){
			case 'csv':
				$attribute = get_object_vars($this->getPrototype()->dataProvider->model);
				$attribute['arClass'] = get_class($this->getPrototype()->dataProvider->model);
				$attribute['cacheId'] = $this->getPrototype()->id;
				$this->htmlOptions['onClick'] = 'javascript:window.location.href="'.Yii::app()->baseUrl.'/system/csv?'.http_build_query($attribute).'"';
				break;
			case 'report':
				$attribute = get_object_vars($this->getPrototype()->dataProvider->model);
				$attribute['arClass'] = get_class($this->getPrototype()->dataProvider->model);
				$attribute['cacheId'] = $this->getPrototype()->id;
				$this->htmlOptions['onClick'] = 'javascript:window.location.href="'.Yii::app()->baseUrl.'/system/report?'.http_build_query($attribute).'"';
				break;
			case 'link':
				$this->htmlOptions['onClick'] = 'javascript:window.location.href="'.$this->url.'"';
				break;
		}
		
	}
	
	
}